// Crc32.cpp: implementation of the CCrc32 class.
#include "stdAfx.h"
#include "Crc32.h"

CCrc32::CCrc32()
{
	CRCInit();
}

CCrc32::~CCrc32()
{

}
void CCrc32::CRCInit()
{
	int I,J; ULONG C;
	for(I=0;I<256;I++)
	{
		for (C = I,J = 0; J < 8; J++)
		{
			C = (C & 1) ? (C >> 1) ^ 0xEDB88320L : (C >> 1);
		}
		CRCTab[I] = C;
	}
}

ULONG CCrc32::CRC32(ULONG StartCRC,UCHAR *Addr,ULONG Size)
{
	StartCRC ^= 0xffffffffL;
	for(ULONG I=0; I<Size; I++)
	{
		StartCRC = CRCTab[(UCHAR)StartCRC ^ Addr[I]] ^ (StartCRC >> 8);
	}
	StartCRC ^= 0xffffffffL;
	return(StartCRC);
}